/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tetris;

import java.awt.*;

/**
 *
 * @author CJ
 */
public abstract class Block {

    protected int x;
    protected int y;
    protected long rate;
    protected char dir;
    protected long lastmove;
    protected boolean stopped;
    protected int[][] boundarea;
    protected Color color;

    protected int WIDTH;
    protected int LENGTH;

    protected boolean shadow;


    public Block()
    {
        x = 150;
        y = 0;
        rate = 500;
        dir = 'N';
        lastmove = System.currentTimeMillis();
        stopped = false;
        WIDTH = 300;
        LENGTH = 500;
        shadow = true;
        makearea();
    }

    public Block(int x, int y, int rate, char dir, int l, int w)
    {
        this.x = x;
        this.y = y;
        this.rate = rate;
        this.dir = dir;
        lastmove = System.currentTimeMillis();
        stopped = false;
        WIDTH = w;
        LENGTH = l;
        shadow = true;
        makearea();
    }

    public Color getColor()
    {
        return color;
    }

    public int[][] getBoundry()
    {
        return boundarea;
    }

    public boolean stop()
    {
        return stopped;
    }

    public int getX()
    {
        return x;
    }

    public int getY()
    {
        return y;
    }

    public long getRate()
    {
        return rate;
    }

    public char getDir()
    {
        return dir;
    }

    public void setDir(char dir)
    {
        this.dir = dir;
    }



    public void setY(int y)
    {
        this.y = y;
        makearea();
    }

    public void stopit()
    {
        stopped = true;
    }

    public void moveit()
    {
        stopped = false;
    }

    public void step(Board b, boolean wait)
    {
        if(!wait)
        {
            y += 10;
            makearea();
        }
        else if(wait && !stopped && System.currentTimeMillis() - lastmove > rate)
        {
            y += 10;
            lastmove = System.currentTimeMillis();
            makearea();
        }
        stopped = !canMoveY(b);
    }

    public void rotate()
    {
        if(dir == 'N')
            dir = 'E';
        else if(dir == 'E')
            dir = 'S';
        else if(dir == 'S')
            dir = 'W';
        else if(dir == 'W')
            dir = 'N';
        makearea();
    }

    public abstract void draw(Graphics g, Board b);    
    public abstract void makearea();
    public abstract boolean canMoveY(Board b);
    public abstract void setX(int x, Board b);
    public abstract void shadowDraw(Graphics g, Board b);
}
